#!/bin/bash
### BEGIN INIT INFO
# Provides:          S99_main
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Main Process
# Description:       This file starts and stops main.py Process
### END INIT INFO

case "$1" in
  start)
    echo "Starting main.py"
    nohup python /root/main.py /root/LZ-Smart-Agriculture.rknn > /root/send.log 2>&1 &
    ;;
  stop)
    echo "Stopping main.py"
    pkill -f "python /root/main.py /root/LZ-Smart-Agriculture.rknn"
    ;;
  restart)
    echo "Restarting main.py LZ-Smart-Agriculture.rknn"
    $0 stop
    $0 start
    ;;
  *)
    echo "Usage: /etc/init.d/S99_main {start|stop|restart}"
    exit 1
    ;;
esac

exit 0
